package day10;

import java.util.Scanner;

public class demo2 {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int prvMin=Integer.MAX_VALUE;
int ret=0;
        for (int i = 0; i <n ; i++) {
          int x=in.nextInt();
            ret=Math.max(ret,x-prvMin);
            prvMin=Math.min(x,prvMin);
        }
        System.out.println(ret<0?0:ret);

    }
}
